package com.exam.controller;

import com.exam.pojo.Student;
import com.exam.pojo.Teacher;
import com.exam.service.TeacherService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class TeacherController {
    @Resource
    private TeacherService teacherService;
    @GetMapping("/teacher/{id}")
    public Teacher getAllById(@PathVariable("id") Integer teacherId){
        return teacherService.queryById(teacherId);
    }
    @GetMapping("/manage/teachers/{pageNum}/{pageSize}")
    public PageInfo<Teacher> getAllById(@PathVariable("pageNum") Integer pageNum,
                                        @PathVariable("pageSize") Integer pageSize){
        return teacherService.queryAllPage(pageNum,pageSize);
    }

    @PutMapping("/manage/teacher/update")
    public int getAllById(@RequestBody Teacher teacher){
        return teacherService.updateById(teacher);
    }
    @DeleteMapping("/manage/teacher/delete/{id}")
    public Boolean deleteById(@PathVariable("id") Integer userId){
        return teacherService.deleteByUserId(userId);
    }
    @GetMapping("/manage/teachers/id")
    public List<Integer> getAllById(){
        return teacherService.queryTeaId();
    }
    @PostMapping("/manage/teacher/add")
    public Boolean add(@RequestBody Teacher teacher){
        try {
            teacherService.insert(teacher);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }
}
